package xyz.xtt.exchange.constants;

import java.util.Arrays;
import java.util.Objects;

import com.google.common.primitives.Ints;

/**
 * 经营证类型
 * 
 * 
 * @author huqibo
 * 
 *         资产状态
 */
public enum CertificateTypeEnum {

	A(AssetTypeEnum.BIZ_CERTIFICATE, 0, "A类"), B(AssetTypeEnum.BIZ_CERTIFICATE, 1, "B类");

	private AssetTypeEnum assetTypeEnum;
	private int code;
	private String desc;

	// 构造函数
	private CertificateTypeEnum(AssetTypeEnum assetTypeEnum, int code, String desc) {
		this.assetTypeEnum = assetTypeEnum;
		this.code = code;
		this.desc = desc;
	}

	public AssetTypeEnum assetType() {
		return assetTypeEnum;
	}

	public int code() {
		return code;
	}

	// 获取描述
	public String desc() {
		return desc;
	}

	public static boolean checkType(String checkType) {
		return Arrays.asList(CertificateTypeEnum.values()).stream().anyMatch(x -> Objects.equals(x.name(), checkType));
	}

	public static CertificateTypeEnum queryConvert(String checkType) {
		return Arrays.asList(CertificateTypeEnum.values()).stream()
				.filter(x -> Objects.equals(x.code(), Ints.tryParse(checkType))).findFirst().orElse(null);
	}

	public static CertificateTypeEnum convert(String checkType) {
		return Arrays.asList(CertificateTypeEnum.values()).stream().filter(x -> Objects.equals(x.name(), checkType))
				.findAny().orElseGet(null);
	}
}
